" __  ____   __  _   ___     _____ __  __ ____   ____
"|  \/  \ \ / / | \ | \ \   / /_ _|  \/  |  _ \ / ___|
"| |\/| |\ V /  |  \| |\ \ / / | || |\/| | |_) | |
"| |  | | | |   | |\  | \ V /  | || |  | |  _ <| |___
"|_|  |_| |_|   |_| \_|  \_/  |___|_|  |_|_| \_\\____|

if exists('g:vscode')
	" ===
	" === Editor behavior
	" ===
	set exrc
	set secure
	set number
	set relativenumber
	set cursorline
	set hidden
	set noexpandtab
	set tabstop=2
	set shiftwidth=2
	set softtabstop=2
	set autoindent
	set list
	set listchars=tab:\|\ ,trail:▫
	set scrolloff=4
	set ttimeoutlen=0
	set notimeout
	set viewoptions=cursor,folds,slash,unix
	set wrap
	set tw=0
	set indentexpr=
	set foldmethod=indent
	set foldlevel=99
	set foldenable
	set formatoptions-=tc
	set splitright
	set splitbelow
	set noshowmode
	set showcmd
	set wildmenu
	set ignorecase
	set smartcase
	set shortmess+=c
	set inccommand=split
	set completeopt=longest,noinsert,menuone,noselect,preview
	set lazyredraw "same as above
	set visualbell

	if exists("&autoread")
		set autoread
	endif
	" up/down keys for 20 times j/k (faster navigation)
	noremap <silent> <UP> 20k
	noremap <silent> <DOWN> 20j

	" n/N keys for 5 times j/k (faster navigation)
	noremap <silent> N 5k
	noremap <silent> n 5j
	
	" ===
	" === Searching
	" ===
	"unmap =
	noremap ( N
	noremap ) n

	" make Y to copy till the end of the line
	nnoremap Y y$

	" Copy to system clipboard
	vnoremap Y "+y

	" Indentation
	nnoremap < <<
	nnoremap > >>





else
	" ====================
	" === Editor Setup ===
	" ====================
	" ===
	" === System
	" ===
	"set clipboard=unnamedplus
	let &t_ut=''
	set autochdir


	" ===
	" === Editor behavior
	" ===
	set exrc
	set secure
	set number
	set relativenumber
	set cursorline
	set hidden
	set noexpandtab
	set tabstop=2
	set shiftwidth=2
	set softtabstop=2
	set autoindent
	set list
	set listchars=tab:\|\ ,trail:▫
	set scrolloff=4
	set ttimeoutlen=0
	set notimeout
	set viewoptions=cursor,folds,slash,unix
	set wrap
	set tw=0
	set indentexpr=
	set foldmethod=indent
	set foldlevel=99
	set foldenable
	set formatoptions-=tc
	set splitright
	set splitbelow
	set noshowmode
	set showcmd
	set wildmenu
	set ignorecase
	set smartcase
	set shortmess+=c
	set inccommand=split
	set completeopt=longest,noinsert,menuone,noselect,preview
	set ttyfast "should make scrolling faster
	set lazyredraw "same as above
	set visualbell
	if exists("&autoread")
		set autoread
	endif
		
	silent !mkdir -p ~/.config/nvim/tmp/backup
	silent !mkdir -p ~/.config/nvim/tmp/undo
	"silent !mkdir -p ~/.config/nvim/tmp/sessions
	set backupdir=~/.config/nvim/tmp/backup,.
	set directory=~/.config/nvim/tmp/backup,.
	if has('persistent_undo')
		set undofile
		set undodir=~/.config/nvim/tmp/undo,.
	endif
	set colorcolumn=100
	set updatetime=100
	set virtualedit=block

	au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif


	" ===
	" === Terminal Behaviors
	" ===
	let g:neoterm_autoscroll = 1
	autocmd TermOpen term://* startinsert
	tnoremap <C-N> <C-\><C-N>
	tnoremap <C-O> <C-\><C-N><C-O>
	let g:terminal_color_0  = '#000000'
	let g:terminal_color_1  = '#FF5555'
	let g:terminal_color_2  = '#50FA7B'
	let g:terminal_color_3  = '#F1FA8C'
	let g:terminal_color_4  = '#BD93F9'
	let g:terminal_color_5  = '#FF79C6'
	let g:terminal_color_6  = '#8BE9FD'
	let g:terminal_color_7  = '#BFBFBF'
	let g:terminal_color_8  = '#4D4D4D'
	let g:terminal_color_9  = '#FF6E67'
	let g:terminal_color_10 = '#5AF78E'
	let g:terminal_color_11 = '#F4F99D'
	let g:terminal_color_12 = '#CAA9FA'
	let g:terminal_color_13 = '#FF92D0'
	let g:terminal_color_14 = '#9AEDFE'


	" ===
	" === Basic Mappings
	" ===
	" Set <LEADER> as <SPACE>, ; as :
	let mapleader=" "
	"noremap ; :

	" Save & quit
	noremap Q :q<CR>
	noremap <C-q> :qa<CR>
	noremap <C-s> :w<CR>
	imap <C-s> <esc>:w<CR>
	noremap R :source ~/.config/nvim/init.vim<CR>

	" Open the vimrc file anytime
	noremap <LEADER>rc :e ~/.config/nvim/init.vim<CR>
	noremap <LEADER>R :e!<CR>

	" Undo operations
	"noremap l u

	" Insert Key
	"noremap k i
	"noremap K I

	" make Y to copy till the end of the line
	nnoremap Y y$

	" Copy to system clipboard
	vnoremap Y "+y

	" Indentation
	nnoremap < <<
	nnoremap > >>

	" Search
	noremap <LEADER><CR> :nohlsearch<CR>

	" Adjacent duplicate words
	noremap <LEADER>dw /\(\<\w\+\>\)\_s*\1

	" Space to Tab
	nnoremap <LEADER>tt :%s/    /\t/g
	vnoremap <LEADER>tt :s/    /\t/g

	" Folding
	noremap <silent> <LEADER>o za

	" Open up lazygit
	noremap \g :Git 
	noremap <c-g> :tabe<CR>:-tabmove<CR>:term lazygit<CR>
	" nnoremap <c-n> :tabe<CR>:-tabmove<CR>:term lazynpm<CR>


	" ===
	" === Cursor Movement
	" ===
	" New cursor movement (the default arrow keys are used for resizing windows)
	"     ^
	"     u
	" < n   i >
	"     e
	"     v
	"noremap <silent> u k
	"noremap <silent> n h
	"noremap <silent> e j
	"noremap <silent> i l
	"noremap <silent> gu gk
	"noremap <silent> ge gj
	"noremap <silent> \v v$h

	noremap <silent> H ^
	noremap <silent> L $

	" up/down keys for 20 times j/k (faster navigation)
	noremap <silent> <UP> 20k
	noremap <silent> <DOWN> 20j

	" n/N keys for 5 times j/k (faster navigation)
	noremap <silent> N 5k
	noremap <silent> n 5j

	" N key: go to the start of the line
	"noremap <silent> N 0
	" I key: go to the end of the line
	"noremap <silent> I $

	" Faster in-line navigation
	noremap W 5w
	noremap B 5b

	" set h (same as n, cursor left) to 'end of word'
	"noremap h e

	" Ctrl + U or E will move up/down the view port without moving the cursor
	noremap <C-u> 5<C-y>
	noremap <C-U> 5<C-e>


	" source $XDG_CONFIG_HOME/nvim/cursor.vim
	source /home/lj/.config/nvim/cursor.vim

	" ===
	" === Insert Mode Cursor Movement
	" ===
	inoremap <C-a> <ESC>A


	" ===
	" === Command Mode Cursor Movement
	" ===
	cnoremap <C-a> <Home>
	cnoremap <C-e> <End>
	cnoremap <C-p> <Up>
	cnoremap <C-n> <Down>
	cnoremap <C-b> <Left>
	cnoremap <C-f> <Right>
	cnoremap <M-b> <S-Left>
	cnoremap <M-w> <S-Right>


	" ===
	" === Searching
	" ===
	noremap - N
	noremap = n


	" ===
	" === Window management
	" ===
	" Use <space> + new arrow keys for moving the cursor around windows
	noremap <LEADER>w <C-w>w
	noremap <LEADER>k <C-w>k
	noremap <LEADER>n <C-w>j
	noremap <LEADER>h <C-w>h
	noremap <LEADER>l <C-w>l

	" Disable the default s key
	noremap s <nop>

	" split the screens to up (horizontal), down (horizontal), left (vertical), right (vertical)
	noremap sk :set nosplitbelow<CR>:split<CR>:set splitbelow<CR>
	noremap sj :set splitbelow<CR>:split<CR>
	noremap sh :set nosplitright<CR>:vsplit<CR>:set splitright<CR>
	noremap sl :set splitright<CR>:vsplit<CR>

	" Resize splits with arrow keys
	noremap <S-up> :res +5<CR>
	noremap <S-down> :res -5<CR>
	noremap <left> :vertical resize-5<CR>
	noremap <right> :vertical resize+5<CR>

	" Place the two screens up and down
	noremap <LEADER>ej <C-w>t<C-w>K
	" Place the two screens side by side
	noremap <LEADER>eh <C-w>t<C-w>H

	" Rotate screens
	noremap srh <C-w>b<C-w>K
	noremap srv <C-w>b<C-w>H

	" Press <SPACE> + q to close the window below the current window
	noremap <LEADER>q <C-w>j:q<CR>


	" ===
	" === Tab management
	" ===
	" Create a new tab with tu
	noremap tu :tabe<CR>
	" Move around tabs with tn and ti
	noremap th :-tabnext<CR>
	noremap tl :+tabnext<CR>
	" Move the tabs with tmn and tmi
	noremap tmh :-tabmove<CR>
	noremap tml :+tabmove<CR>


	" ===
	" === Markdown Settings
	" ===
	" Snippets
	"source $XDG_CONFIG_HOME/nvim/md-snippets.vim
	" auto spell
	"autocmd BufRead,BufNewFile *.md setlocal spell


	" ===
	" === Other useful stuff
	" ===
	" Open a new instance of st with the cwd
	"nnoremap \t :tabe<CR>:-tabmove<CR>:term sh -c 'st'<CR><C-\><C-N>:q<CR>

	" Move the next character to the end of the line with ctrl+9
	inoremap <C-u> <ESC>lx$p

	" Opening a terminal winrow
	noremap <LEADER>/ :set splitbelow<CR>:split<CR>:res +10<CR>:term<CR>

	" Press space twice to jump to the next '' and edit it
	" noremap <LEADER><LEADER> <Esc>/<CR>:nohlsearch<CR>c4l
	inoremap jj <Esc>

	" Spelling Check with <space>sc
	noremap <LEADER>sc :set spell!<CR>

	" Press ` to change case (instead of ~)
	"noremap ` ~

	noremap <C-c> zz

	" Auto change directory to current dir
	autocmd BufEnter * silent! lcd %:p:h

	" Call figlet
	noremap tx :r !figlet 

	" find and replace
	noremap \s :%s//g<left><left>

	" set wrap
	noremap <LEADER>sw :set wrap<CR>

	" press f10 to show hlgroup
	function! SynGroup()
		let l:s = synID(line('.'), col('.'), 1)
		echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
	endfun
	map <F10> :call SynGroup()<CR>



	" ===
	" === Install Plugins with Vim-Plug
	" ===

	call plug#begin('~/.config/nvim/plugged')

	" Plug 'LoricAndre/fzterm.nvim'

	" Testing my own plugin
	" Plug 'theniceboy/vim-calc'

	" Treesitter
	"Plug 'nvim-treesitter/nvim-treesitter'
	"Plug 'nvim-treesitter/playground'

	" Pretty Dress
	Plug 'bpietravalle/vim-bolt'
	Plug 'theniceboy/nvim-deus'
	"Plug 'arzg/vim-colors-xcode'

	" Status line
	Plug 'theniceboy/eleline.vim'
	Plug 'ojroques/vim-scrollstatus'

	" General Highlighter
	Plug 'RRethy/vim-hexokinase', { 'do': 'make hexokinase' }
	Plug 'RRethy/vim-illuminate'

	" TagBar
	Plug 'preservim/tagbar'

	" File navigation
	"Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
	Plug 'preservim/nerdtree'
	Plug 'preservim/nerdcommenter'
	Plug 'Xuyuanp/nerdtree-git-plugin'
	Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
	Plug 'junegunn/fzf.vim'
	Plug 'Yggdroot/LeaderF', { 'do': './install.sh' }
	Plug 'kevinhwang91/rnvimr'
	Plug 'airblade/vim-rooter'
	Plug 'pechorin/any-jump.vim'

	" Auto Complete
	Plug 'neoclide/coc.nvim', {'branch': 'release'}
	" Plug 'neoclide/coc.nvim', {'branch': 'release', 'tag': 'v0.0.78'}
	Plug 'wellle/tmux-complete.vim'

	" For general w
	Plug 'mg979/vim-visual-multi', {'branch': 'master'}
	" https://github.com/mg979/vim-visual-multi
	Plug 'tpope/vim-surround'

	" emmet
	Plug 'mattn/emmet-vim'


	" Markdown
	"Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
	"Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle', 'for': ['text', 'markdown', 'vim-plug'] }
	"Plug 'mzlogin/vim-markdown-toc', { 'for': ['gitignore', 'markdown', 'vim-plug'] }
	"Plug 'dkarter/bullets.vim'
	Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install'  }

	" HTML, CSS, JavaScript, Typescript, PHP, JSON, etc.
	Plug 'elzr/vim-json'
	" Plug 'hail2u/vim-css3-syntax' " , { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
	" Plug 'spf13/PIV', { 'for' :['php', 'vim-plug'] }
	" Plug 'pangloss/vim-javascript', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
	Plug 'yuezk/vim-js', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
	" Plug 'MaxMEllon/vim-jsx-pretty', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
	" Plug 'jelera/vim-javascript-syntax', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
	"Plug 'jaxbot/browserlink.vim'
	" Plug 'HerringtonDarkholme/yats.vim'
	" Plug 'posva/vim-vue'
	" Plug 'evanleck/vim-svelte', {'branch': 'main'}
	" Plug 'leafOfTree/vim-svelte-plugin'
	" Plug 'leafgarland/typescript-vim'

	" Go
	Plug 'fatih/vim-go' , { 'for': ['go', 'vim-plug'], 'tag': '*' }
	Plug 'nsf/gocode', { 'rtp': 'nvim', 'do': '~/.config/nvim/plugged/gocode/nvim/symlink.sh' }

	" Auto Save
	Plug '907th/vim-auto-save'

	call plug#end()
	set re=0

	" experimental
	set lazyredraw
	"set regexpengine=1


	" ===
	" === TagBar
	" ===
	nmap T :TagbarToggle<CR><leader>l



	" ===
	" === vim-instant-markdown
	" ===
	"let g:instant_markdown_slow = 1
	"let g:instant_markdown_autostart = 1
	"let g:instant_markdown_open_to_the_world = 1
	"let g:instant_markdown_allow_unsafe_content = 1
	"let g:instant_markdown_allow_external_content = 0
	"let g:instant_markdown_mathjax = 1
	"let g:instant_markdown_autoscroll = 1



	" ===
	" === markdown-preview
	" ===
	" let g:mkdp_auto_start = 1
	" let g:mkdp_auto_close = 1
	" let g:mkdp_refresh_slow = 0
	" let g:mkdp_command_for_global = 0
	" let g:mkdp_open_to_the_world = 0
	" let g:mkdp_open_ip = ''
	" let g:mkdp_browser = ''
	" let g:mkdp_echo_preview_url = 0
	" let g:mkdp_browserfunc = ''



	" ===
	" === vim-table-mode
	" ===
	noremap <LEADER>tm :TableModeToggle<CR>
	"let g:table_mode_disable_mappings = 1
	let g:table_mode_cell_text_object_i_map = 'k<Bar>'




	" ===
	" === emmet
	" ===
	let g:user_emmet_leader_key='<C-y>'


	" ===
	" === nerdcommenter
	" ===
	" https://github.com/preservim/nerdcommenter

	let g:NERDCreateDefaultMappings = 1
	let g:NERDSpaceDelims = 1
	let g:NERDCompactSexyComs = 1
	let g:NERDDefaultAlign = 'left'
	let g:NERDAltDelims_java = 1
	let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
	let g:NERDCommentEmptyLines = 1
	let g:NERDTrimTrailingWhitespace = 1
	let g:NERDToggleCheckAllLines = 1

	" ===
	" === NERDTree
	" ===
	map tt :NERDTreeToggle<CR>
	"let NERDTreeMapOpenExpl = ""
	"let NERDTreeMapUpdir = ""
	"let NERDTreeMapUpdirKeepOpen = ""
	"let NERDTreeMapOpenSplit = ""
	"let NERDTreeMapOpenVSplit = ""
	"let NERDTreeMapActivateNode = "i"
	"let NERDTreeMapOpenInTab = "o"
	"let NERDTreeMapOpenInTabSilent = "O"
	"let NERDTreeMapPreview = ""
	"let NERDTreeMapCloseDir = ""
	"let NERDTreeMapChangeRoot = "l"
	"let NERDTreeMapMenu = ","
	"let NERDTreeMapToggleHidden = "zh"

	"let NERDTreeMapOpenExpl = ""
	"let NERDTreeMapUpdir = "h"
	"let NERDTreeMapUpdirKeepOpen = ""
	"let NERDTreeMapOpenSplit = "sl"
	"let NERDTreeMapOpenVSplit = "vL"
	"let NERDTreeMapActivateNode = "i"
	"let NERDTreeMapOpenInTab = "L"
	"let NERDTreeMapOpenInTabSilent = "l"
	"let NERDTreeMapPreview = "p"
	"let NERDTreeMapCloseDir = "c"
	"let NERDTreeMapChangeRoot = "o"
	"let NERDTreeMapMenu = ","



	"let g:NERDTreeMapCustomOpen      ='<CR>'
	let g:NERDTreeMapCustomOpen      ='l'
	let g:NERDTreeMapActivateNode    ='o'
	let g:NERDTreeMapChangeRoot      ='C'
	let g:NERDTreeMapChdir           ='cd'
	let g:NERDTreeMapCloseChildren   ='X'
	let g:NERDTreeMapCloseDir        ='x'
	let g:NERDTreeMapDeleteBookmark  ='D'
	let g:NERDTreeMapMenu            ='m'
	let g:NERDTreeMapHelp            ='?'
	let g:NERDTreeMapJumpFirstChild  ='K'
	let g:NERDTreeMapJumpLastChild   ='J'
	"let g:NERDTreeMapJumpNextSibling ='<C-j>'
	let g:NERDTreeMapJumpParent      ='h'
	"let g:NERDTreeMapJumpPrevSibling ='<C-k>'
	let g:NERDTreeMapJumpRoot        ='H'
	let g:NERDTreeMapOpenExpl        ='e'
	"let g:NERDTreeMapOpenInTab       ='t'
	let g:NERDTreeMapOpenInTab       ='l'
	"let g:NERDTreeMapOpenInTabSilent ='T'
	let g:NERDTreeMapOpenInTabSilent ='L'
	"let g:NERDTreeMapOpenRecursively ='O'
	let g:NERDTreeMapOpenSplit       ='vl'
	let g:NERDTreeMapOpenVSplit      ='sl'
	"let g:NERDTreeMapPreview        =''
	"let g:NERDTreeMapPreviewSplit   =''
	"let g:NERDTreeMapPreviewVSplit  =''
	let g:NERDTreeMapQuit            ='q'
	let g:NERDTreeMapRefresh         ='r'
	let g:NERDTreeMapRefreshRoot     ='R'
	let g:NERDTreeMapToggleBookmarks ='B'
	let g:NERDTreeMapToggleFiles     ='F'
	let g:NERDTreeMapToggleFilters   ='f'
	let g:NERDTreeMapToggleHidden    ='I'
	let g:NERDTreeMapToggleZoom      ='A'
	let g:NERDTreeMapUpdir           ='u'
	let g:NERDTreeMapUpdirKeepOpen   ='U'
	"let g:NERDTreeMapCWD             ='CD'
	let g:NERDTreeMenuDown           ='j'
	let g:NERDTreeMenuUp             ='k'
	let g:NERDTreeMapToggleHidden      = "zh"



	" ===
	" === coc.nvim
	" ===
	let g:coc_global_extensions = [
		\ 'coc-actions',
		\ 'coc-explorer',
		\ 'coc-css',
		\ 'coc-diagnostic',
		\ 'coc-gitignore',
		\ 'coc-html',
		\ 'coc-json',
		\ 'coc-lists',
		\ 'coc-prettier',
		\ 'coc-pyright',
		\ 'coc-snippets',
		\ 'coc-sourcekit',
		\ 'coc-stylelint',
		\ 'coc-syntax',
		\ 'coc-tasks',
		\ 'coc-todolist',
		\ 'coc-translator',
		\ 'coc-tslint-plugin',
		\ 'coc-tsserver',
		\ 'coc-vetur',
		\ 'coc-vimlsp',
		\ 'coc-yaml',
		\ 'coc-yank']
	inoremap <silent><expr> <TAB>
		\ pumvisible() ? "\<C-n>" :
		\ <SID>check_back_space() ? "\<TAB>" :
		\ coc#refresh()
	inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
	inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
	function! s:check_back_space() abort
		let col = col('.') - 1
		return !col || getline('.')[col - 1]  =~# '\s'
	endfunction
	inoremap <silent><expr> <c-space> coc#refresh()
	inoremap <silent><expr> <c-o> coc#refresh()
	function! Show_documentation()
		call CocActionAsync('highlight')
		if (index(['vim','help'], &filetype) >= 0)
			execute 'h '.expand('<cword>')
		else
			call CocAction('doHover')
		endif
	endfunction
	nnoremap <A-h> :call Show_documentation()<CR>
	" set runtimepath^=~/.config/nvim/coc-extensions/coc-flutter-tools/
	" let g:coc_node_args = ['--nolazy', '--inspect-brk=6045']
	" let $NVIM_COC_LOG_LEVEL = 'debug'
	" let $NVIM_COC_LOG_FILE = '/Users/david/Desktop/log.txt'

	nnoremap <silent><nowait> <LEADER>d :CocList diagnostics<cr>
	nmap <silent> <LEADER>- <Plug>(coc-diagnostic-prev)
	nmap <silent> <LEADER>= <Plug>(coc-diagnostic-next)
	nnoremap <c-c> :CocCommand<CR>
	" Text Objects
	xmap kf <Plug>(coc-funcobj-i)
	xmap af <Plug>(coc-funcobj-a)
	omap kf <Plug>(coc-funcobj-i)
	omap af <Plug>(coc-funcobj-a)
	xmap kc <Plug>(coc-classobj-i)
	omap kc <Plug>(coc-classobj-i)
	xmap ac <Plug>(coc-classobj-a)
	omap ac <Plug>(coc-classobj-a)
	" Useful commands
	nnoremap <silent> <space>y :<C-u>CocList -A --normal yank<cr>
	nmap <silent> gd <Plug>(coc-definition)
	nmap <silent> gy <Plug>(coc-type-definition)
	" nmap <silent> gi <Plug>(coc-implementation)
	nmap <silent> gr <Plug>(coc-references)
	nmap <leader>rn <Plug>(coc-rename)
	"nmap tt :CocCommand explorer<CR>

	" coc-translator
	nmap ts <Plug>(coc-translator-p)
	" Remap for do codeAction of selected region
	function! s:cocActionsOpenFromSelected(type) abort
		execute 'CocCommand actions.open ' . a:type
	endfunction
	xmap <silent> <leader>a :<C-u>execute 'CocCommand actions.open ' . visualmode()<CR>
	nmap <silent> <leader>a :<C-u>set operatorfunc=<SID>cocActionsOpenFromSelected<CR>g@
	" coctodolist
	nnoremap <leader>tn :CocCommand todolist.create<CR>
	nnoremap <leader>tl :CocList todolist<CR>
	nnoremap <leader>tu :CocCommand todolist.download<CR>:CocCommand todolist.upload<CR>
	" coc-tasks
	noremap <silent> <leader>ts :CocList tasks<CR>
	" coc-snippets
	imap <C-l> <Plug>(coc-snippets-expand)
	vmap <C-e> <Plug>(coc-snippets-select)
	let g:coc_snippet_next = '<c-e>'
	let g:coc_snippet_prev = '<c-n>'
	imap <C-e> <Plug>(coc-snippets-expand-jump)
	let g:snips_author = 'Jason Len'
	autocmd BufRead,BufNewFile tsconfig.json set filetype=jsonc


	" Mini Vim-APP
	"Plug 'jceb/vim-orgmode'
	"Plug 'mhinz/vim-startify'
	"Plug 'skywind3000/asynctasks.vim'
	"Plug 'skywind3000/asyncrun.vim'


	" ===
	" === Startify
	" ===
	"let g:startify_lists = [
	"		 \{'type':'files',			'header': ['  MRU']},
	"		 \{'type':'bookmarks',	'header': ['  Bookmarks']},
	"		 \{'type':'commands', 	'header': ['  Commands']}, ]



	" ==
	" == vim-multiple-cursor
	" ==
	"let g:multi_cursor_use_default_mapping = 0
	"let g:multi_cursor_start_word_key = '<c-k>'
	"let g:multi_cursor_select_all_word_key = '<a-k>'
	"let g:multi_cursor_start_key = 'g<c-k>'
	"let g:multi_cursor_select_all_key = 'g<a-k>'
	"let g:multi_cursor_next_key = '<c-k>'
	"let g:multi_cursor_prev_key = '<c-p>'
	"let g:multi_cursor_skip_key = '<C-s>'
	"let g:multi_cursor_quit_key = '<Esc>'

	" ===
	" === Auto Save
	" ===
	"let g:auto_save=1
	"let g:auto_save_events=["TextChanged", "InsertLeave"]
	" ===
	" === FZF
	" ===
	set rtp+=/usr/lOcal/opt/fzf
	set rtp+=/home/linuxbrew/.linuxbrew/opt/fzf
	set rtp+=/home/lj/.linuxbrew/opt/fzf
	nnoremap <c-p> :Leaderf file<CR>
	" noremap <silent> <C-p> :Files<CR>
	noremap <silent> <C-f> :Rg<CR>
	noremap <silent> <C-h> :History<CR>
	"noremap <C-t> :BTags<CR>
	noremap <silent> <C-l> :Lines<CR>
	"noremap <silent> <C-w> :Buffers<CR>
	noremap <leader>; :History:<CR>

	let g:fzf_preview_window = 'right:60%'
	let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'

	function! s:list_buffers()
		redir => list
		silent ls
		redir END
		return split(list, "\n")
	endfunction

	function! s:delete_buffers(lines)
		execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]}))
	endfunction

	command! BD call fzf#run(fzf#wrap({
		\ 'source': s:list_buffers(),
		\ 'sink*': { lines -> s:delete_buffers(lines) },
		\ 'options': '--multi --reverse --bind ctrl-a:select-all+accept'
	\ }))

	noremap <c-d> :BD<CR>

	let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.8 } }

endif
